package binary_tree.leetcode.medium;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author bruin_du
 * @description 二叉搜索树迭代器
 * @date 2022/8/15 23:01
 **/
public class OfferII055_BSTIterator {
    Queue<Integer> queue = new LinkedList<>();
    public OfferII055_BSTIterator(TreeNode root) {
        inorder(root);
    }

    private void inorder(TreeNode root) {
        if (root == null) return;
        inorder(root.left);
        queue.offer(root.val);
        inorder(root.right);
    }

    public int next() {
        if (queue.isEmpty()) return 0;
        else return queue.poll();
    }

    public boolean hasNext() {
        return !queue.isEmpty();
    }
}
